// pages/question/question.js
const app = getApp();
const API_URL = 'https://api.lailiaosheji.com/'
import api from '../../utils/api.js';
Page({

  /**
   * 页面的初始数据
   */
  data: {
    questionTab: [
      { text: '题库', icon: '/images/question.png', selectedIcon: '/images/question_active.png' },
      { text: '历史', icon: '/images/history.png', selectedIcon: '/images/history_active.png' },
      { text: '我的', icon: '/images/my.png', selectedIcon: '/images/my_active.png' }
    ],
    currentTabbarIndex: 0,
    swiperArr:[1,2,3],

    questionList:[]
  },

  change(e) {
    this.setData({
      currentTabbarIndex: e.currentTarget.dataset.index
    })
    if (this.data.currentTabbarIndex == 0) {
      wx.redirectTo({
        url: '/pages/question/question',
      })
    } else if (this.data.currentTabbarIndex == 1) {
      wx.redirectTo({
        url: '/pages/history/history',
      })
    } else {
      wx.redirectTo({
        url: '/pages/my/my',
      })
    }

  },

  // 请求轮播图片
  getSwiper() {
    api.POST('/applet/RotationChart/finds', {}, res => {
      console.log(res)
      this.setData({
        swiperArr: res.data.data
      })
    })
  },
  //预览轮播图
  previewImage(e) {
    wx.previewImage({
      urls: [API_URL + e.currentTarget.dataset.rotation_chart_url]
    })
  },
  
  getQuestionList(){
    api.POST('applet/paperCategory/finds', { "first_id": 0},(res)=>{
      console.log(res)
      this.setData({
        questionList: res.data.data
      })
    })
  },

  goToSubjectDetail(e){
    wx.navigateTo({
      url: '/pages/subjectDetail/subjectDetail?paper_category_id=' + e.currentTarget.dataset.paper_category_id + '&name=' + e.currentTarget.dataset.name,
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.getQuestionList()
    this.getSwiper()
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})